home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 331_01 / block.c < prev    next >
Text File  |  1990-06-12  |  11KB  |  424 lines

  1. /*
  2. HEADER:         CUG199.06;
  3. TITLE:          GED (nee QED) screen editor -- part six;
  4. DATE:           12/15/86;
  5.  
  6. DESCRIPTION:   "Block operation commands for the GED editor";
  7. KEYWORDS:       block operations;
  8. SYSTEM:         MS-DOS;
  9. FILENAME:       GED6.C;
  10. AUTHORS:        G. Nigel Gilbert, James W. Haefner,  Mel Tearle, G. Osborn;
  11. COMPILERS:      Microsoft 4.0;
  12. */
  13.  
  14. /*
  15.      e/qed/ged  screen editor
  16.  
  17.     (C) G. Nigel Gilbert, MICROLOGY, 1981
  18.            August-December 1981
  19.  
  20.     Modified:  Aug-Dec   1984:   BDS-C 'e'(vers 4.6a) to 'qe' (J.W. Haefner)
  21.                March     1985:   BDS-C 'qe' to DeSmet-C 'qed' (J.W. Haefner)
  22.                May       1986:   converted to ged - Mel Tearle
  23.  
  24.     FILE:      ged6.c
  25.  
  26.     FUNCTIONS: blockpos, blockops, putpart, listfile
  27.  
  28.     PURPOSE:   performs block commands
  29.  
  30. */
  31.  
  32. #include <stdio.h>
  33. #include "ged.h"
  34.  
  35.  
  36. blockpos(oldpos)
  37. int  oldpos;
  38. {
  39.     unsigned char getkey();
  40.     char  c;
  41.     int to;
  42.  
  43.     do  {
  44.         switch ( (c = getkey()) )  {
  45.         case DOWNKEY :
  46.             moveline(1);
  47.             break;
  48.         case UPKEY :
  49.             moveline(-1);
  50.             break;
  51.         case LEFTKEY :
  52.             movechar(-1);
  53.             break;
  54.         case RIGHTKEY :
  55.             movechar(1);
  56.             break;
  57.         case LEFTWKEY :
  58.             moveword(-1);
  59.             break;
  60.         case RIGHTWKEY :
  61.             moveword(1);
  62.             break;
  63.         case BOLKEY :
  64.             sync(0);
  65.             break;
  66.         case EOLKEY :
  67.             sync(strlen(text));
  68.             break;
  69.         case UPPAGE :
  70.             movepage(-1);
  71.             break;
  72.         case DOWNPAGE :
  73.             movepage(0);
  74.             break;
  75.         case HOMEKEY :
  76.             jumpline(lastl-cline);
  77.             break;
  78.         case BOFKEY :
  79.             jumpline(1-cline);
  80.             break;
  81.         case JUMPKEY :
  82.             dojump();
  83.             break;
  84.         case QWIKKEY :
  85.             info();
  86.             break;
  87.         case REPKEY :
  88.             repeat = YES;
  89.             dofindrep(1);
  90.             repeat = NO;
  91.             break;
  92.         case 'p' :
  93.         case 'P' :
  94.             if ( oldpos )  return  PREV;
  95.             break;
  96.         case ESCKEY :
  97.             return  FAIL;
  98.         default :
  99.             ;
  100.         }
  101.     }
  102.     while ( c != CR );
  103.     return  cline;
  104. }
  105.  
  106.  
  107. /* 'K'- key block options
  108.  * some mods to print routine - mt.
  109.  */
  110. blockops()
  111. {
  112.     unsigned char getkey();
  113.     int   oldcline, oldcharn, oldto, oldfrom, op;
  114.     int   l, ll, line, *t, shifts, shiftx, cp;
  115.     char  *txt, c, shift[LLIM];
  116.  
  117.     puttext();
  118.     blankedmess = YES;  /* disable time of day display */
  119.     oldcline = cline;
  120.     oldcharn = charn;
  121.     oldfrom  = vbord1;
  122.     oldto    = vbord2;
  123.  
  124.     putmess("|Q|uit, e|X|it with save, |R|ead file, |B|lock/output operations ");
  125.     while ( (op = getlow()) != 'q'  &&  op != 'x'  &&  op != 'r' &&
  126.         op != 'b'  &&  op != 'j' &&
  127.         op != ESCKEY );
  128.     if ( op == ESCKEY  )
  129.         return;
  130.  
  131.     putch(op);
  132.     switch (op)  {
  133.     case 'q':
  134.         return('q');
  135.         break;
  136.     case 'x':
  137.         return('x');
  138.         break;
  139.     case 'r':
  140.         putmess("Wait");
  141.         return('r');
  142.         break;
  143.     case F7KEY:
  144.         return  (NO);
  145.         break;
  146.     default:
  147. /* block commands */
  148.         vbord1 = cline;
  149.         vbord2 = 0;      /* use updated cline for second limit */
  150.         blocking = YES;
  151.  
  152.         putline(cline, cursory, NULL);  /* reverse field current line */
  153.         putmess( "Move cursor then press <return>");
  154.  
  155.         if (blockpos(oldto) == FAIL) {
  156.             goto abort;
  157.         }
  158.         if ( vbord2 == PREV )  {
  159.             moveline( oldfrom-cline );
  160.             vbord1 = cline;
  161.             moveline( oldto-cline );
  162.             vbord2 = cline;
  163.         }
  164.         if (vbord2 == 0)
  165.             vbord2 = cline;
  166.  
  167.         if ( vbord2 < vbord1 )  {
  168.             l = vbord2;
  169.             vbord2 = vbord1;
  170.             vbord1 = l;
  171.         }
  172.  
  173.  
  174.         putmess("|W|rite to file, |P|rint, |S|hift, |M|ove, |C|opy, or |D|elete block ? ");
  175.         while ((op=getlow()) != 'w' && op != 'p' && op != 's' && op != 'm'
  176.             && op != 'c' && op != 'd' && op != ESCKEY);
  177.  
  178.         switch (op)  {
  179.         case ESCKEY:
  180.            goto abort;
  181.            break;
  182.         case 'w':
  183.             putmess( " File to write to? ");
  184.             if ( scans( name, FILELEN ) != ESCKEY )
  185.                 if ( exists( name ) )
  186.                     writefile( vbord1, vbord2, name, name );
  187.             break;
  188.  
  189.         case 'p':
  190.             if ( !prnstat() )
  191.                 goto abort;      /* add 12/13/86 */
  192.             cleareol( 0, 0 );
  193.             putstatusline( vbord1 );
  194.             listfile( vbord1, vbord2 );
  195.             putmess( "Any |Function Key| to form feed ");
  196.             c = getkey();
  197.             if ( c >= F1KEY  &&  c <= F10KEY )
  198.                 listout(  0x0c );
  199.             break;
  200.  
  201.         case 's':
  202.             charn=0;
  203.             moveline( vbord1 - cline );
  204.             putmess( "Insert or delete spaces/tabs to shift block, press <return>");
  205.             shifts = 0;
  206.             while ( (c = getkey()) != CR )  {
  207.                 switch (c)  {
  208.                 case DELRIGHT:
  209.                     if ( text[0] == ' ' || text[0] == '\t' )
  210.                         deletechar(0);
  211.                     break;
  212.                 case ' ':
  213.                     insertchar(' ');
  214.                     break;
  215.                 case TAB:
  216.                     insertchar('\t');
  217.                     break;
  218.                 case ESCKEY:
  219.                     goto abort;
  220.                 }
  221.                 shift[shifts++] = c;
  222.                 sync(0);
  223.                 rewrite(0);
  224.             }
  225.             puttext();
  226.             for ( l = vbord1 + 1; l <= vbord2; l++ )  {
  227.                 gettext(l, charn);
  228.                 for ( shiftx = 0; shiftx < shifts; shiftx++ )  {
  229.                     switch( ( c = shift[shiftx] ) )  {
  230.                     case DELRIGHT:
  231.                         if ( *(txt=&text[0]) == ' ' || *txt == '\t' )
  232.                             while ( (*txt=*(txt+1)) ) txt++;
  233.                         break;
  234.                     case ' ':
  235.                     case TAB:
  236.                         if ( (cp = strlen( text ) ) < (LLIM-1) )  {
  237.                             for ( ; cp >= 0; cp-- )
  238.                                 text[cp+1]=text[cp];
  239.                             text[0] = ( c == ' ' ? ' ': '\t' );
  240.                         }
  241.                         break;
  242.                     }
  243.                 }
  244.                 altered = YES;
  245.                 puttext();
  246.             }
  247.             break;
  248.  
  249. /* block delete */
  250.         case 'd':
  251.             deltp( vbord1, vbord2-vbord1+1 );
  252.             blocking = NO;
  253.             plast = -1;
  254.             moveline(vbord1-cline);
  255.             break;
  256.  
  257. /* block copy or move */
  258.         case 'm':
  259.         case 'c':
  260.             if (op == 'm')
  261.                 putmess("Put cursor under |move| destination and press <return>");
  262.             else
  263.                 putmess("Put cursor under |copy| destination and press <return>");
  264.             if ( (line = blockpos(0)) == FAIL )  {
  265.                 break;
  266.             }
  267.             putmess("Wait");
  268.             line--;
  269.             for ( l = vbord1; l <= vbord2; l++ )  {
  270.                 if ( (line = inject( line, getline(l)) ) == FAIL )
  271.                     break;
  272.                 if ( op == 'm' )  {
  273.                     deltp( ( l < line ? l : l + 1 ), 1 );
  274.                     if ( vbord2 < line )  {
  275.                         vbord2--;
  276.                         l--;
  277.                         line--;
  278.                         cline--;
  279.                     }
  280.                 }
  281.                 else {
  282.                     if (vbord2 >= line)
  283.                         vbord2++;
  284.                     if (l >= line)
  285.                         l++;
  286.                     if (l == cline)
  287.                         l = line;
  288.                 }
  289.             }
  290.  
  291.             vbord1 = cline;
  292.